<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>=API接口调试页面=</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	 <link rel="stylesheet" href="./static/ztree/zTreeStyle/zTreeStyle.css" type="text/css">
	 <script type="text/javascript" src="./static/js/jquery.min.js"></script>
	 <script type="text/javascript" src="./static/ztree/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript">
  <!--
	var zTree;
	var demoIframe;
	var seperator = " ";

	var setting = {
		view: {
			dblClickExpand: false,
			showLine: true,
			selectedMulti: false,
			expandSpeed: ($.browser.msie && parseInt($.browser.version)<=6)?"":"fast"
		},
		data: {
			simpleData: {
				enable:true,
				idKey: "id",
				pIdKey: "pId",
				rootPId: ""
			}
		},
		callback: {
			onClick: function(event, treeId, treeNode, clickFlag) {
				var zTree = $.fn.zTree.getZTreeObj("tree");
				if (treeNode.isParent) {
					zTree.expandNode(treeNode);
					return false;
				} else {
				 	var nodeName = resetNodeName(treeNode.id,treeNode.name);
				 	nodeName = encodeURIComponent(nodeName);
					demoIframe.attr("src",treeNode.file+"?apiId="+treeNode.id+"&apiName="+nodeName);
					return true;
				}
			}
		}
	};

	var zNodes =[
		{id:0, pId:-1, name:"readme",  file:"${ctx }/readme.html"},
		
		{id:1, pId:-1, name:"用户", open:true},
		{id:101, pId:1, name:"用户登录", file:"${ctx }/api/mobile/login.jsp"},
		{id:102, pId:1, name:"用户注销", file:"${ctx }/api/mobile/logout.jsp"},
		{id:103, pId:1, name:"检查用户名是否存在", file:"./api/check-username.jsp"}
		
	];

	$(document).ready(function(){
		setNodeName(zNodes);
		var t = $("#tree");
		t = $.fn.zTree.init(t, setting, zNodes);
		demoIframe = $("#content");
		demoIframe.bind("load", loadReady);
		var zTree = $.fn.zTree.getZTreeObj("tree");
		zTree.selectNode(zTree.getNodeByParam("id", -1));
	});

	function loadReady() {
		var bodyH = demoIframe.contents().find("body").get(0).scrollHeight,
		htmlH = demoIframe.contents().find("html").get(0).scrollHeight,
		maxH = Math.max(bodyH, htmlH), minH = Math.min(bodyH, htmlH),
		h = demoIframe.height() >= maxH ? minH:maxH ;
		if (h < 530) h = 530;
		demoIframe.height(h);
	}
	
	function setNodeName(zNodes) {
		var len = zNodes.length;
		for(var i=0;i<len;i++){
			zNodes[i].name = zNodes[i].id+seperator+zNodes[i].name;
		}
	}
	
	function resetNodeName(nodeId,nodeName) {
		if(nodeName!=null&&nodeName!=""){
			var prefix = nodeId+seperator;
			var start = prefix.length;
			var end = nodeName.length;
			return nodeName.substring(start,end);
		}else{
			return nodeName;
		}
	}
  //-->
</script>
  </head>  
  <body style="width: 100%;">
   		<table width="100%;" style="width: 100%;height: 100%" >
   			<tr>
   				<td style="border-right: #999999 1px dashed;width: 260px;vertical-align: top;">
   					<ul id="tree" class="ztree" style="width:260px; overflow:auto;"></ul>
   				</td>
   				<td height="100%" style="vertical-align: top;">
   					<iframe id="content" name="content" frameborder="0" width="100%" height="100%" src="./readme.html"></iframe>
   				</td>
   			</tr>
   		</table>
  </body>
</html>
